﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Content.Pipeline;
using Tomahawk.Resources.LightningBolts;
using System.IO;
using System.Xml.Serialization;

namespace Tomahawk.Processors
{
    #region XML Particle Settings Collection Importer
    /// <summary>
    /// Creates an ParticleSettingsCollection from an XML serialization
    /// </summary>
    [ContentImporter(".xml", DefaultProcessor = "LightningDescriptorProcessor",
          DisplayName = "XML Lightning Descriptor Importer - Tomahawk Engine")]
    public class LightningDescriptorImporter : ContentImporter<LightningDescriptor>
    {
        public override LightningDescriptor Import(string filename, ContentImporterContext context)
        {
            LightningDescriptor output = null;

            try
            {
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    XmlSerializer x = new XmlSerializer(typeof(LightningDescriptor));
                    output = (LightningDescriptor)x.Deserialize(fs);
                }
            }
            catch
            {
                throw new InvalidContentException("Unknown error while importing the XML content file");
            }

            return output;
        }
    }
    #endregion
}
